<template>
  <div class="flowpath-container">
    <div>
      <div class="mb20">
        <span class="color_494949 ft12 pr5">{{ translate('入库单名称') }}：</span>
        <el-input
          v-model="searchInfo"
          class="w164 mr10"
          :placeholder="translate('请输入名称')"
        />
        <span class="color_494949 ft12 pr5">{{ translate('部门名称') }}：</span>
        <el-input
          v-model="searchInfo1"
          class="w164 mr10"
          :placeholder="translate('请输入部门信息')"
        />
        <span class="color_494949 ft12 pr5">{{ translate('单号') }}：</span>
        <el-input
          v-model="searchInfo2"
          class="w164 mr10"
          :placeholder="translate('请输入单号')"
        />
        <span class="color_494949 ft12 pr5 w70">{{ translate('审核状态') }}：</span>
        <el-select
          v-model="Remark"
          class="w164 mr10"
          :placeholder="translate('请选择')"
         >
          <el-option
            v-for="item in RemarkArry"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
          </el-select>
          <span class="color_494949 ft12 pr5">{{ translate('创建人') }}：</span>
          <el-input
            v-model="searchInfo4"
            class="w164 mr10"
            :placeholder="translate('请输入关键字')"
          />
          <div class="condition-container">
            <div class="condition">
              <span class="w70 color_494949 ft12 pr5">{{ translate('时间') }}：</span>
              <el-date-picker
                v-model="searchInfo3"
                end-placeholder="结束日期"
                range-separator="至"
                start-placeholder="开始日期"
                type="daterange"
                value-format="YYYY-MM-DD"
              />
            </div>
          </div>
        <el-button class="settingBtn ml10" type="primary" @click="getList">
          {{ translate('查询') }}
        </el-button>
        <el-button class="settingBtn ml10" type="primary" @click="resetFn()">
          {{ translate('重置') }}
        </el-button>
      </div>
      <div class="add">
        <el-button
          v-if="MenuAuths('add')"
          class="settingBtn"
          type="primary"
          @click="addFn"
          plain
        >
          {{ translate('新增') }}
        </el-button>
        <el-upload
          accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"
          :action="action"
          :before-upload="beforeUpload"
          class="ml-upload"
          :headers="headers"
          name="fileInput"
          :on-error="handleError"
          :on-success="handleSuccess"
          :show-file-list="false"
        >
          <ElButton plain type="primary" @click="uploadFn()">
            {{ translate('生产物资导入') }}
          </ElButton>
        </el-upload>
        <el-upload
          accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"
          :action="action1"
          :before-upload="beforeUpload"
          class="ml-upload"
          :headers="headers1"
          :data="fromtype"
          name="fileInput"
          :on-error="handleError"
          :on-success="handleSuccess"
          :show-file-list="false"
        >
          <ElButton plain type="primary" @click="uploadFn1('应急物资')">
            {{ translate('应急物资导入') }}
          </ElButton>
        </el-upload>
        <el-upload
          accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"
          :action="action1"
          :before-upload="beforeUpload"
          class="ml-upload"
          :headers="headers1"
          :data="fromtype"
          name="fileInput"
          :on-error="handleError"
          :on-success="handleSuccess"
          :show-file-list="false"
        >
          <ElButton plain type="primary" @click="uploadFn1('劳保物资')">
            {{ translate('劳保物资导入') }}
          </ElButton>
        </el-upload>
        <el-upload
          accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"
          :action="action1"
          :before-upload="beforeUpload"
          class="ml-upload"
          :headers="headers1"
          :data="fromtype"
          name="fileInput"
          :on-error="handleError"
          :on-success="handleSuccess"
          :show-file-list="false"
        >
          <ElButton plain type="primary" @click="uploadFn1('消防物资')">
            {{ translate('消防物资导入') }}
          </ElButton>
        </el-upload>
        <el-button
          class="settingBtn ml10"
          type="primary"
          @click="batchFn"
          plain
        >
          {{ translate('批量审核') }}
        </el-button>
      </div>
      <el-table :data="tableData"
                v-loading="loading"
                :row-class-name="tableRowClassName"
                :row-key="getRowKey"
                @selection-change="handleSelectionChange">
        <el-table-column prop="value" type="selection" width="55" />
        <!-- <el-table-column label="序号" type="index" width="80" /> -->
        <!-- <el-table-column :label="translate('入库单名称')" prop="FullName" /> -->
        <!-- <el-table-column label="库点名称" prop="WHName" show-overflow-tooltip /> -->
        <el-table-column :label="translate('入库编码')">
          <template #default="{ row }">
            <div>
              <span class="iconcolor">{{ row.Code }}</span>
              <vab-icon icon="file-copy-line" @click="copyToClipboard(row.Code)" />
            </div>
          </template>
        </el-table-column>
        <!-- <el-table-column :label="translate('来源单据号')" prop="SourceBillNo" /> -->
        <!-- <el-table-column :label="translate('业务类型')" prop="IBType">
          <template #default="{ row }">
            <div>
              {{
                row.IBType === '1'
                  ? translate('委托仓储入库')
                  : row.IBType === '2'
                  ? translate('正常入库')
                  : ''
              }}
            </div>
          </template>
        </el-table-column> -->
        <el-table-column
          :label="translate('供货单位')"
          prop="Supplier"
          show-overflow-tooltip
        />
        <el-table-column
          :label="translate('入库时间')"
          prop="InComeDate"
          show-overflow-tooltip
        />
        <el-table-column
          :label="translate('制单人')"
          prop="Documenter"
          show-overflow-tooltip
        />
        <!-- <el-table-column
          :label="translate('合同编号')"
          prop="CCode"
          show-overflow-tooltip
        /> -->
        <el-table-column :label="translate('审核状态')">
          <template #default="{ row }">
            <el-tag type="success" v-if="row.MaterialReceiver === '已审核'">{{ row.MaterialReceiver }}</el-tag>
            <el-tag type="info" v-if="row.MaterialReceiver && row.MaterialReceiver !== '已审核'">{{ row.MaterialReceiver }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          :label="translate('创建人')"
          prop="CreateUserName"
          show-overflow-tooltip
        />
        <el-table-column
          :label="translate('创建时间')"
          prop="CreateDate"
          show-overflow-tooltip
          width="170"
        />
        <el-table-column :label="translate('操作')" width="350">
          <template #default="{ row }">
            <el-button plain size="small" type="primary" @click="examineFn(row)" :disabled="row.isdisable === null? false : row.isdisable">
              {{ translate('审核') }}
            </el-button>
            <el-button
              plain
              size="small"
              type="primary"
              @click="outFN(row)"
              :disabled="row.isdisable1 === null? false : row.isdisable1"
            >
              {{ translate('反审') }}
            </el-button>
            <el-button
              v-if="MenuAuths('edit')"
              plain
              size="small"
              type="primary"
              @click="detailFn(row)"
            >
              {{ translate('编辑') }}
            </el-button>
            <el-button plain size="small" type="primary" @click="print(row)">
              {{ translate('打印') }}
            </el-button>

            <el-button
              v-if="MenuAuths('delete') && row.MaterialReceiver !== '已审核'"
              plain
              size="small"
              type="danger"
              @click="deletedFn(row)"
            >
              {{ translate('删除') }}
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination">
        <el-pagination
          background
          :current-page="pageNo"
          :layout="layout"
          :page-size="pageSize"
          :total="total"
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange"
        />
      </div>
    </div>
    <el-dialog
      v-model="dialogVisible"
      :title="translate('物资入库单')"
      width="1220px"
      @close="closeFn"
      :close-on-click-modal="false"
    >
      <i v-if="status === 1" class="iconfont icon-shenhezhong iconcommon"></i>
      <i v-if="status === 2" class="iconfont icon-yishenhe iconcommon2"></i>
      <detail
        :agreementlist="agreementList"
        :chileddetail="chileddetail"
        :form="form"
        fromtype="goodslist"
        :purchaselist="PurchaseList"
        :supplierdata="SupplierData"
        :whdata="WHdata"
        @changelist="changeList"
        @deletedchild="deletedchild"
      />
      <template #footer>
        <el-button @click="dialogVisible = false">
          {{ translate('取消') }}
        </el-button>
        <el-button :disabled="isclick" type="primary" @click="submit">
          {{ translate('确定') }}
        </el-button>
      </template>
    </el-dialog>
    <!-- 打印页面 -->
    <el-dialog
      v-model="isPrint"
      center
      width="1350px"
      @close="isPrint = false"
      :close-on-click-modal="false"
    >
      <print
        ref="tableRef"
        :chileddetail="chileddetail"
        :form="form"
        fromprint="goodsList"
        :supplierdata="SupplierData"
      />
      <template #footer>
        <el-button @click="isPrint = false">{{ translate('取消') }}</el-button>
        <el-button type="primary" @click="submitPrint">
          {{ translate('打印') }}
        </el-button>
      </template>
    </el-dialog>
    <wordflow
      :drawershow="isdrawershow"
      :formid="formId"
      :nodelist="nodeList"
      @handclose="handleClose"
    />
  </div>
</template>

<script>
  import {
    BillMasterList,
    delibm,
    UpdateData,
    AddData,
    GetDetailPageData,
    Wms_SupplierData,
    agreePageData,
    Wms_PurchaseList,
    startflow,
    auditwms,
    getinstance,
    WHGetPageData,
    IncomeBillExamine,
    InComeCancel,
    InComeBatchData,
  } from '@/api/form'
  import detail from './components/detail'
  import wordflow from '@/views/components/wordflow/index'
  import print from './components/print'
  import { MenuAuth } from '~/src/utils/permission'
  import VabPrint from '@/plugins/VabPrint'
  import { translate } from '@/i18n'
  import { useUserStore } from '@/store/modules/user'
  import { baseURL } from '@/config'
  import { parseTime } from '@/utils'
  import { BaseGetPageData } from '@/api/item'
  const { token, accountInfo } = useUserStore()
  export default defineComponent({
    name: 'Flowpath',
    components: { detail, print, wordflow },
    data() {
      return {
        tableData: [],
        searchInfo: '',
        searchInfo1: '',
        searchInfo2: '',
        searchInfo3: '',
        searchInfo4: '',
        fromtype: '',
        total: 0,
        pageNo: 1,
        pageSize: 20,
        dialogVisible: false,
        enabled: 0,
        DetailPageData: {},
        chileddetail: [],
        SupplierData: [], // 供货商单位
        submitType: 'add',
        layout: 'total, sizes, prev, pager, next, jumper',
        deleList: [],
        MenuAuths: '',
        tableRef: null,
        isPrint: false,
        loading: false,
        agreementList: [],
        PurchaseList: [],
        isdrawershow: false,
        nodeList: {},
        formId: '',
        status: -1,
        WHdata: [],
        action: '',
        action1: '',
        headers: '',
        headers1: '',
        isclick: false,
        Remark: '全部',
        selectArr: [],
        isdisable: false,
        form: {
          IBType: '',
          InComeNo: '',
          AcceptanceNo: '',
          SourceBillNo: '',
          Supplier: '',
          CCode: '',
          EntrustNo: '',
          CustomizeNo: '',
          ProjectName: '',
          WorkBillNo: '',
          AcceptanceConclusion: '',
          CategoryNumber: '',
          InComeDate: '',
          PurchaseNo: '',
          Description: '',
          Documenter: '',
          MaterialReceiver: '',
          FinancialReviewer: '',
        },
        RemarkArry: [
          {
            label: '全部',
            value: '全部'
          },
          {
            label: '已审核',
            value: '已审核'
          },
          {
            label: '未审核',
            value: '未审核'
          },
          {
            label: '已反审核',
            value: '已反审核'
          }
        ],
        rules: {
          code: [
            {
              required: true,
              trigger: 'blur',
              message: translate('请输入工号'),
            },
          ],
          Account: [
            {
              required: true,
              trigger: 'blur',
              message: translate('请输入登录账号'),
            },
          ],
          workFlowName: [
            {
              required: true,
              trigger: 'blur',
              message: translate('请输入账号名称'),
            },
          ],
        },
      }
    },
    created() {
      this.MenuAuths = MenuAuth
      this.searchInfo = sessionStorage.getItem('GLsearchInfo') || ''
      this.searchInfo1 = sessionStorage.getItem('GLsearchInfo1') || ''
      this.searchInfo3 = JSON.parse(sessionStorage.getItem('GLsearchInfo3')) || []
      this.searchInfo2 = sessionStorage.getItem('GLsearchInfo2') || ''
      this.searchInfo4 = sessionStorage.getItem('GLsearchInfo4') || ''
      this.Remark = sessionStorage.getItem('GLRemark') || ''
      if(this.searchInfo3.length<=0 || !this.searchInfo3) {
        this.searchInfo3 = [this.getFirstDayOfMonthFormatted(),this.getLastDayOfMonth()]
                console.log(this.getFirstDayOfMonthFormatted())
                console.log(this.getLastDayOfMonth())
      }
      this.getList()
    },
    methods: {
      getLastDayOfMonth() {
      // 创建一个当前日期的副本
          let date = new Date();

          // 设置日期为下个月的第一天（这样可以跳过本月所有日期）
          date.setDate(1);
          date.setMonth(date.getMonth() + 1);
          date.setDate(0); // 这会将日期设置为上一个月的最后一天

          // 格式化日期为 YYYY-MM-DD
          let year = date.getFullYear();
          let month = String(date.getMonth() + 1).padStart(2, '0'); // 月份是从0开始的，所以要加1
          let day = String(date.getDate()).padStart(2, '0');

          return `${year}-${month}-${day}`;
      },
      getFirstDayOfMonthFormatted() {
            const today = new Date(); // 获取当前日期
            const year = today.getFullYear(); // 获取年份
            const month = today.getMonth(); // 获取月份（注意：0表示1月，11表示12月）
            const date = 1; // 设置日期为1（即当前月份的第一天）

            // 创建日期对象
            const firstDay = new Date(year, month, date);

            // 手动格式化日期为 YYYY-MM-DD
            const formattedDate = `${year.toString().padStart(4, '0')}-${(month + 1).toString().padStart(2, '0')}-${date.toString().padStart(2, '0')}`;
            return formattedDate;
        },

      resetFn() {
        this.searchInfo = ''
        this.searchInfo1 = ''
        this.searchInfo2 = []
        this.searchInfo3 = ''
        this.searchInfo4 = ''
        this.Remark = '全部'
        this.pageNo = 1
        this.pageSize = 20
        sessionStorage.removeItem('GLsearchInfo')
        sessionStorage.removeItem('GLsearchInfo1')
        sessionStorage.removeItem('GLsearchInfo2')
        sessionStorage.removeItem('GLsearchInfo3')
        sessionStorage.removeItem('GLsearchInfo4')
        sessionStorage.removeItem('GLRemark')
        this.getList()
      },
      batchFn() {
        if(this.selectArr.length<=0){
          this.$message({
            message: translate('请选择要审核的单据'),
            type: 'warning',
          })
          return
        }else {
          this.$confirm(translate('确认提交审核?'), translate('提示'), {
          confirmButtonText: translate('确定'),
          cancelButtonText: translate('取消'),
          type: 'warning',
        })
          .then(() => {
            console.log(this.selectArr)
            this.InComeBatch()
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: translate('已取消删除'),
            })
          })
        }
      },
      async InComeBatch() {
        const formIdArr = []
        this.selectArr.map((item,index) =>{
             formIdArr.push(
              {
                formId: item.IBMID
              }
             )
        })
        const params = formIdArr
        const data = await InComeBatchData(params)
        if(data.result.code === '200'){
          this.$message({
            message: translate('已提交审核'),
            type: 'success',
          })
          this.getList()
        }else {
          this.$message({
            message: data.result.message,
            type: 'error',
          })
        }
        console.log(data)
      },
      async uploadFn() {
        this.headers = this.headers = {
          Authorization: `Bearer ${token}`,
        }
        this.action = `${baseURL}/Wms_IncomeBillMaster/ImportNew`
      },
       async uploadFn1(value) {
        this.headers1 = this.headers1 = {
          Authorization: `Bearer ${token}`,
        }
        this.fromtype = {
            EntrustNo: value
        }
        this.action1 = `${baseURL}/Wms_IncomeBillMaster/Import_In_yjwz`
      },
      handleError(data) {
        console.log(data)
      },
      handleSuccess(data) {
        console.log(data)
        if (data.code === '200') {
          this.$message({
            type: 'success',
            message: data.message,
          })
          this.getList()
        } else {
          this.$message({
            message: data.message,
            type: 'error',
          })
        }
      },
      translate(row) {
        return translate(row)
      },
      handleClose() {
        this.isdrawershow = false
      },
      async examineFn(row) {
        this.$confirm(translate('确认提交?'), translate('提示'), {
          confirmButtonText: translate('确定'),
          cancelButtonText: translate('取消'),
          type: 'warning',
        })
          .then(() => {
            this.IncomeBillExamines(row)
            row.isdisable = true
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: translate('已取消删除'),
            })
          })

        // const params = {
        //   keyValue: row.IBMID,
        //   code: 'Wms_IncomeBillMaster',
        //   formUrl: 'outboundBill',
        //   flowData: null,
        // }
        // const data = await startflow(params)
        // if (data.code === '200') {
        //   // this.auditwms('Wms_IncomeBillMaster', row.IBMID)
        //   this.formId = row.IBMID
        //   this.$router.push({
        //     path: '/table/detail',
        //     query: {
        //       formId: this.formId,
        //       formcode: 'Wms_IncomeBillMaster',
        //     },
        //   })
        // } else {
        //   this.$message({
        //     message: data.message,
        //     type: 'error',
        //   })
        // }
      },
      async auditwms(Code, id) {
        const params = {
          code: Code,
          keyValue: id,
        }
        const data = await auditwms(params)
        if (data.code === '200') {
          this.nodeList = data.data
          this.isdrawershow = true
        } else {
          this.$message({
            message: data.message,
            type: 'error',
          })
        }
      },
      async print(row) {
        this.form = row
        this.IBMID = row.IBMID
        await this.GetDetailPageData()
        await this.Wms_SupplierData()
        this.isPrint = true
      },
      async submitPrint() {
        await VabPrint(this.$refs.tableRef)
      },
      changeList(val) {
        this.chileddetail = val?.PurchaseOrderDetail
        this.form = {
          IBType: val.IBType,
          InComeNo: val.InComeNo,
          AcceptanceNo: val.AcceptanceNo,
          SourceBillNo: val.SourceBillNo,
          Supplier: val.Supplier,
          CCode: val.CCode,
          EntrustNo: val.EntrustNo,
          CustomizeNo: val.CustomizeNo,
          ProjectName: val.ProjectName,
          WorkBillNo: val.WorkBillNo,
          AcceptanceConclusion: val.AcceptanceConclusion,
          CategoryNumber: val.CategoryNumber,
          InComeDate: val.InComeDate,
          PurchaseNo: val.PurchaseNo,
          Description: val.Description,
          Documenter: val.Documenter,
          MaterialReceiver: val.MaterialReceiver,
          FinancialReviewer: val.FinancialReviewer,
        }
      },
      async Wms_PurchaseList() {
        const params = {
          pageNo: this.pageNo,
          pageSize: this.pageSize,
          tableName: '',
          sort: '',
          order: '',
          wheres: '',
          export: true,
          value: '',
        }
        const data = await Wms_PurchaseList(params)
        if (data.code === '200') {
          this.PurchaseList = data.data.rows
        }
      },
      async getList() {
        this.loading = true
        const params = {
          pageNo: this.pageNo,
          pageSize: this.pageSize,
          tableName: '',
          sort: '',
          order: '',
          wheres: JSON.stringify([
            { name: 'FullName', value: this.searchInfo, displayType: 'like' },
            { name: 'DepartmentName', value: this.searchInfo1, displayType: 'like' },
            { name: 'Code', value: this.searchInfo2, displayType: 'like' },
            { name: 'CreateUserName', value: this.searchInfo4, displayType: 'like' },
            { name: 'MaterialReceiver', value: this.Remark === '全部' ? '' : this.Remark, displayType: 'like' },
            { name: 'InComeDate', value: this.searchInfo3 ? this.searchInfo3[0]+' 00:00:00' : '', displayType: 'ThanOrEqual' },
            { name: 'InComeDate', value: this.searchInfo3 ? this.searchInfo3[1]+' 23:59:59' : '', displayType: 'LessOrequal' }
          ]),
          export: false,
          value: '',
        }
        sessionStorage.setItem('GLsearchInfo', this.searchInfo)
        sessionStorage.setItem('GLsearchInfo1', this.searchInfo1)
        sessionStorage.setItem('GLsearchInfo2', this.searchInfo2)
        sessionStorage.setItem('GLsearchInfo4', this.searchInfo4)
        sessionStorage.setItem('GLRemark', this.Remark)
        sessionStorage.setItem('GLsearchInfo3', JSON.stringify(this.searchInfo3))
        const data = await BillMasterList(params)
        this.tableData = data.data.rows
        this.total = data.data.total
        console.log(this.tableData)
        this.loading = false
      },
      deletedchild(e) {
        this.deleList = e
        console.log(e)
      },
      async deletedFn(row) {
        this.$confirm(translate('确认删除该文件吗?'), translate('提示'), {
          confirmButtonText: translate('确定'),
          cancelButtonText: translate('取消'),
          type: 'warning',
        })
          .then(() => {
            this.deleted(row)
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: translate('已取消删除'),
            })
          })
      },
      async deleted(row) {
        const IbmID = []
        IbmID.push(row.IBMID)
        const params = IbmID
        const data = await delibm(params)
        if (data.code == '200') {
          this.$message({
            message: translate('删除成功'),
            type: 'success',
          })
          await this.getList()
        }
      },
      async agreePageData() {
        const params = {
          pageNo: this.pageNo,
          pageSize: this.pageSize,
          tableName: '',
          sort: '',
          order: '',
          wheres: '',
          export: true,
          value: '',
        }
        const data = await agreePageData(params)
        this.agreementList = data.data.rows
      },
      //分页条数切换
      handleSizeChange(val) {
        this.pageSize = val
        this.getList()
      },
      //分页切换
      handleCurrentChange(val) {
        this.pageNo = val
        this.getList()
      },
      tableRowClassName({ row, rowIndex }) {
        row.row_index = rowIndex
      },
      handleSelectionChange(e) {
        this.selectArr = e
      },
      getRowKey(row) {
        return row.IBMID
      },
      //复制标识
      async copyToClipboard(val) {
        if (navigator.clipboard && window.isSecureContext) {
          try {
          console.log(navigator.clipboard)
          console.log(window.isSecureContext)
          await navigator.clipboard.writeText(val)
          this.$message({
            message:'复制成功',
            type:'success',
          })
          } catch (err) {
            this.$message({
            message:'复制失败',
            type:'error',
          })
          }

        }else {
          // 创建text area
        const textArea = document.createElement("textarea")
        textArea.value = val
        // 使text area不在viewport，同时设置不可见
        textArea.style.position = "absolute"
        textArea.style.opacity = 0
        textArea.style.left = "-999999px"
        textArea.style.top = "-999999px"
        document.body.appendChild(textArea)
        textArea.focus()
        textArea.select()

        return new Promise((res, rej) => {
          // 执行复制命令并移除文本框
          document.execCommand("copy") ? res() : rej()
          textArea.remove()
        }).then(() => {
          this.$message({
              message: "复制成功",
              type: "success",
            })
          }).catch((err) => {
            this.$message({
              message: "复制失败",
              type: "error",
            })
          })
        }

  },
      async addFn() {
        console.log(accountInfo)
        this.submitType = 'add'
        this.dialogVisible = true
        this.status = -1
        this.form = {
          IBType: '',
          InComeNo: '',
          AcceptanceNo: '',
          SourceBillNo: '',
          Supplier: '',
          CCode: '',
          EntrustNo: '',
          CustomizeNo: '',
          ProjectName: '',
          WorkBillNo: '',
          AcceptanceConclusion: '',
          CategoryNumber: '',
          InComeDate: '',
          PurchaseNo: '',
          Description: '',
          Documenter: accountInfo.realName,
          MaterialReceiver: '',
          FinancialReviewer: accountInfo.realName,
          SupID: accountInfo.departmentName,
        }
        await this.Wms_SupplierData()
        await this.WHGetPageData()
        // await this.agreePageData()
        // await this.Wms_PurchaseList()

        this.chileddetail = []
        this.deleList = []
      },
      submit() {
        if (this.status === 1 || this.status === 2) {
          const messages =
            this.status === 1
              ? '单据审核中，不允许修改！'
              : '单据已审核，不允许修改'
          this.$message({
            message: messages,
            type: 'warning',
          })
          return
        }
        if(this.chileddetail&&this.chileddetail.length>0) {
          let isreturn = false
          this.chileddetail.map((item) =>{
            if(item.SupName === ''|| item.SupName.trim() === '' || item.SupName === null ||item.SupName === 'null') {
              isreturn = true
            }
          })
          if(isreturn) {
            this.$message({
                message: '厂家必填，请填写',
                type: 'warning',
              })
              return
          }
        }
        if (this.submitType === 'add') {
          this.AddData()
        } else {
          this.updataSaveList()
        }
      },
      outFN(row) {
        this.$confirm(translate('确认反审核该订单?'), translate('提示'), {
          confirmButtonText: translate('确定'),
          cancelButtonText: translate('取消'),
          type: 'warning',
        })
          .then(() => {
            row.isdisable1 = true
            this.outexamineFn(row)
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: translate('已取消删除'),
            })
          })
      },
      async outexamineFn(row) {
        this.loading = true
        const params = {
          formId: row.IBMID,
        }
        const data = await InComeCancel(params)
        this.$message({
          message: data.result.message ? data.result.message : '未知错误',
          type: 'success',
        })
        this.loading = false
        setTimeout(() => {
          row.isdisable1 = false
         this.getList()
        },30000)

      },
      closeFn() {
        this.enabled = 0
        this.form.WorkFlowID = ''
      },
      async IncomeBillExamines(row) {
        this.loading = true
        const params = {
          code: 'Wms_IncomeBillMaster',
          formId: row.IBMID,
        }
        const data = await IncomeBillExamine(params)
        if (data.result.code === '200') {
          this.loading = false
          this.$message({
            message: translate('提交成功'),
            type: 'success',
          })
        }else{
          this.loading = false
          this.$message({
            message: data.result.message,
            type: 'error',
          })
        }
        setTimeout(() => {
          row.isdisable = false
          this.getList()
        },30000)
      },
      async detailFn(row) {
        this.deleList = []
        row.SupID = row.DepartmentName
        this.form = row
        this.IBMID = row.IBMID
        this.submitType = 'edit'
        await this.getinstances(row)
        await this.GetDetailPageData()
        await this.Wms_SupplierData()
        // await this.agreePageData()
        // await this.Wms_PurchaseList()
        await this.WHGetPageData()
        this.dialogVisible = true
      },
      async WHGetPageData() {
        const params = {
          pageNo: 1,
          pageSize: 20,
          wheres: `[{"name":"ModuleId","value":"","displayType":"equal"}]`,
          export: true,
          moduleType: 'ModuleId',
          sort: 'SortCode',
          order: 'ASC',
          search: '',
        }
        const data = await WHGetPageData(params)
        if (data.data.rows && data.data.rows.length > 0) {
          data.data.rows.map((item) => {
            item.value = item.FullName
          })
        }
        this.WHdata = data.data.rows
      },
      async getinstances(row) {
        const params = {
          code: 'Wms_IncomeBillMaster',
          formId: row.IBMID,
        }
        const data = await getinstance(params)
        if (data.code === '200') {
          this.status = data.data?.data?.status
        }
      },
      async Wms_SupplierData() {
        const params = {
          pageNo: 1,
          pageSize: 100,
          tableName: '',
          sort: '',
          order: '',
          wheres: '',
          export: true,
          value: '',
        }
        const data = await BaseGetPageData(params)
        this.SupplierData = data.data.rows
      },
      async GetDetailPageData() {
        const params = {
          pageNo: 1,
          pageSize: 100,
          total: 0,
          tableName: '',
          sort: '',
          order: '',
          wheres: '',
          export: true,
          value: this.IBMID,
        }
        const data = await GetDetailPageData(params)
        if (data.master) {
          this.$nextTick(() => {
            this.chileddetail = data.rows
          })
        }
        console.log(data)
      },
      async AddData() {
        this.isclick = true
        this.form.EntrustNo = this.form.EntrustNo === '全部'?'':this.form.EntrustNo
        const params = {
          mainData: this.form,
          detailData: this.chileddetail,
          delKeys: [],
        }
        const data = await AddData(params)
        if (data.code == '200') {
          this.getList()
          this.$message({
            message: translate('保存成功'),
            type: 'success',
          })
          this.dialogVisible = false
        }
        setTimeout(() => {
          this.isclick = false
        }, 5000)
      },
      async updataSaveList() {
        this.form.EntrustNo = this.form.EntrustNo === '全部'?'':this.form.EntrustNo
        const params = {
          mainData: this.form,
          detailData: this.chileddetail,
          delKeys: this.deleList,
        }
        const data = await UpdateData(params)
        if (data.code == '200') {
          this.getList()
          this.$message({
            message: translate('保存成功'),
            type: 'success',
          })
          this.dialogVisible = false
        }
      },
    },
  })
</script>
<style lang="scss" scoped>
  .flowpath-container {
    .color_494949 {
      display: inline-block;
      width: 85px;
      color: #494949;
      text-align: right;
    }
    .w164 {
      width: 164px;
    }
    .mb20 {
      margin-bottom: 20px;
    }
    .mr10 {
      margin-right: 10px;
    }

    .iconcommon {
      position: absolute;
      top: 80px;
      right: 70px;
      font-size: 60px;
      color: blue;
    }
    .iconcommon2 {
      position: absolute;
      top: 80px;
      right: 70px;
      font-size: 60px;
      color: red;
    }
    .ml-upload {
      display: inline-block;
      margin-left: 10px;
      vertical-align: bottom;
    }
    .add {
      margin-bottom: 10px;
      text-align: left;
    }
    .condition-container {
      margin-top: 10px;
      margin-bottom: 20px;
    }
    .ml10 {
      margin-left: 10px;
    }
    .iconcolor {
      color: #409eff;
    }
    .color_l {
      color: #67c23a;
    }
    .color_red {
      color: #f56c6c;
    }
  }
</style>
